#include "../curl/CurlClient.h"
#include "../http/HttpData.h"
#include "../common/global.h"
#include "../common/CCReactor.h"
#include <iostream>
#include <thread>
#include <chrono>

int main() {
    std::cout << "=== Basic CurlClient Test ===" << std::endl;
    
    try {
        // Initialize reactor
        g_reactor->Init();
        g_reactor->Start();
        
        std::cout << "Reactor initialized" << std::endl;
        
        // Test basic CurlClient creation
        {
            std::cout << "Creating CurlClient..." << std::endl;
            CurlClient client;
            if (!client.Initialize()) {
                std::cout << "Failed to initialize CurlClient" << std::endl;
                return 1;
            }
            std::cout << "CurlClient initialized successfully" << std::endl;
        }
        
        std::cout << "Basic test passed" << std::endl;
        
        // Test with actual request
        {
            std::cout << "Testing HTTP request..." << std::endl;
            CurlClient client;
            if (!client.Initialize()) {
                std::cout << "Failed to initialize CurlClient for request" << std::endl;
                return 1;
            }
            
            stHttpRequest req;
            req.method = "GET";
            req.url = "http://httpbin.org/get";
            req.heads["User-Agent"] = "TestClient/1.0";
            
            stHttpResponse resp;
            int result = client.Request(std::move(req), resp);
            
            std::cout << "Request completed with result: " << result << std::endl;
            if (result == 0) {
                std::cout << "Request successful!" << std::endl;
            }
        }
        
        g_reactor->Stop();
        std::cout << "All tests passed!" << std::endl;
        
    } catch (const std::exception& e) {
        std::cout << "Test failed with exception: " << e.what() << std::endl;
        return 1;
    }
    
    return 0;
}